//
//  MLWTipsVideoCell.m
//  KITCHEN_STORIES
//
//  Created by 孟令通 on 16/6/7.
//  Copyright © 2016年 MLW. All rights reserved.
//

#import "MLWTipsVideoCell.h"

@implementation MLWTipsVideoCell

- (void)dealloc
{
    [_tipsImageView release];
    [_nameLabel release];
    [_likeLabel release];
    [_collectLabel release];
    [_playImage release];
    
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.tipsImageView = [[UIImageView alloc] init];
        
        [self.contentView addSubview:_tipsImageView];
        [_tipsImageView release];
        
        self.mask = [[UIView alloc] init];
        
        [self.contentView addSubview:_mask];
        [_mask release];
        
        self.nameLabel = [[UILabel alloc] init];
        
        [self.contentView addSubview:_nameLabel];
        [_nameLabel release];
        
        self.likeLabel = [[UILabel alloc] init];
        
        [self.contentView addSubview:_likeLabel];
        [_likeLabel release];
        
        
        self.collectLabel = [[UILabel alloc] init];
        
        [self.contentView addSubview:_collectLabel];
        [_collectLabel release];;
        
        
        self.playImage = [[UIImageView alloc] init];
        
        [self.contentView addSubview:_playImage];
        [_playImage release];
        
        
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.tipsImageView makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
        
    }];
    
    self.tipsImageView.contentMode = UIViewContentModeScaleAspectFill;
    
    self.tipsImageView.clipsToBounds = YES;
    
    
    
    [self.mask makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
        
    }];
    
    self.mask.backgroundColor = [UIColor colorWithRed:0.04 green:0.04 blue:0.04 alpha:0.40];
    
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(12.5);
        
        make.top.equalTo(self.contentView).offset(111);
        
        make.height.equalTo(30);
        
        make.width.equalTo(200);
        
    }];
    
    self.nameLabel.textColor = [UIColor whiteColor];

    [self.nameLabel setFont:[UIFont systemFontOfSize:20]];
    
    [self.likeLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.nameLabel.bottom).offset(2);
        
        make.left.equalTo(self.contentView).offset(12.5);
        
        make.height.equalTo(20);
        
        make.width.equalTo(80);
        
    }];
    
    self.likeLabel.textColor = [UIColor whiteColor];

    [self.likeLabel setFont:[UIFont systemFontOfSize:12]];
    
    [self.collectLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.nameLabel.bottom).offset(2);
        
        make.left.equalTo(self.likeLabel.right).offset(12.5);
        
        make.height.equalTo(20);
        
        make.width.equalTo(80);
        
        
    }];
    
    self.collectLabel.textColor = [UIColor whiteColor];

    [self.collectLabel setFont:[UIFont systemFontOfSize:12]];
    
    [self.playImage makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.contentView).offset(-12);
        
        make.bottom.equalTo(self.contentView).offset(-15);
        
        make.width.equalTo(20);
        
        make.height.equalTo(20);
        
    }];
    
    self.playImage.image = [UIImage imageNamed:@"tipsPlay"];
    
    
}

// 重写model的set方法
-(void)setModel:(MLWTipsICookVideoModel *)model
{
    if (_model != model) {
        
        [_model release];
        
        _model = [model retain];
        
        NSURL *url = [NSURL URLWithString:_model.image];
        
        [self.tipsImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"buttonGreen"]];
        
        self.nameLabel.text = _model.dishes_name;
        
//        self.collectLabel.text = [NSString stringWithFormat:@"%@ 人收藏",  _model.collectCount];
        
        self.likeLabel.text = [NSString stringWithFormat:@"%ld 人点赞", _model.like];
        
    }
}


    
@end
